package com.myPractice.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.entity.Result;
import com.itheima.pojo.Spec;
import com.myPractice.dao.SpecMapper;
import com.myPractice.service.SpecService;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class SpecServiceImpl extends ServiceImpl<SpecMapper, Spec> implements SpecService {

    @Override
    public Result<List<Spec>> findAll() {
        List<Spec> list = this.list();

        return new Result<List<Spec>>(true,null,list);
    }

    @Override
    public Result updateSpec(Spec spec) {
        LambdaUpdateWrapper<Spec> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(Spec::getId,spec.getId());
        if (spec.getName()!=null&&!spec.getName().trim().equals("")){
            wrapper.set(Spec::getName,spec.getName());
        }
        if (spec.getOptions()!=null&&!spec.getOptions().trim().equals("")){
            wrapper.set(Spec::getOptions,spec.getOptions());
        }
        if (spec.getSeq()!=null){
            wrapper.set(Spec::getSeq,spec.getSeq());
        }
        boolean update = update(wrapper);
        return new Result(update,null);
    }
}
